/**
 * @Copyright (c) 2005 
 * @All rights reserved.
 *
 *
 *
 * @file_name   Message.js
 * @version     1.0
 * @author      黄新泽
 * @date        2007-10-08 16:09:40
 */

/**
 * Class and Function List:
 * Function list:
 * - function onscrollOpration(ev)         
 * - initialize : function(id, msg, state) 
 * - showMessage : function()              
 * - removeMessage : function()            
 * - failure : function()                  
 * - isSet : function(arg)                 
 * Classes list:
 * - .Message
 */


//圆角DIV
//var roundCorners = Rico.Corner.round.bind(Rico.Corner);

document.write('<div   id="message_contain"  class="m_container"></div>');

function onscrollOpration(ev)
{
	Position.prepare();
	scrollTopSize = Position.deltaY;

	$("message_contain").style.top = (scrollTopSize	+ 22) +	"px";

};

Event.observe(window, 'scroll', onscrollOpration, false);

var	Message = Class.create();
Message.prototype	= 
{

	initialize : function(id, msg, state) 
	{
		this.messageState			= state						;	//是否显示提示消息
		//this.messageState			= false						;	//是否显示提示消息
		this.messageId				= id						;	//提示消息ID
		this.loadMessage			= msg						;
		this.loadCount				= 0							;
	},


	showMessage : function()
	{
		if (!this.messageState)
		{
			return false;
		}

		if ('mask' == this.messageState)
		{
			mask.addMsgWindow();
		}
		else
		{
			this.loadCount++ ; 
			var html='<div id="'+this.messageId+'" class="m_message"> '+this.loadCount+":"+this.loadMessage+'</div>';


			var msg= this.loadCount+":"+this.loadMessage;

			if(1 == this.loadCount)
			{
				new Insertion.Top($('message_contain'), html);
			}
			else
			{
				try	
				{
					$(this.messageId).innerHTML	= msg;
				}
				catch (e)
				{
					this.loadCount -= 2;
				}
				
			}

			html = msg = null;

			setTimeout(this.removeMessage.bind(this), 16000);
		}
	},

	removeMessage : function()
	{
		if (!this.messageState)
		{
			return false;
		}

		if ('mask' == this.messageState)
		{
			mask.removeMsg();
		}
		else
		{
			if(this.loadCount < 1)
			{
				return ;
			}

			this.loadCount-- ;

			var msg = this.loadCount + ":" + this.loadMessage ;
			
			if(this.loadCount	< 1)
			{
				//alert(this.messageId);
				Element.remove(this.messageId);
			}
			else
			{
				//alert(this.messageId+":>1");
				try	
				{
					$(this.messageId).innerHTML	= msg;
				}
				catch (e)
				{
					this.loadCount--;
				}
			}
		}


	},

	failure : function()
	{
		var	eR = '';

		if (!$A(arguments))
		{
			eR = ' 失败!';

			if (this.isSet(this.errorMessage))
			{
				eR = '未成功 <br />原因：' + this.errorMessage; 
			}
		}
		else
		{
			eR = '';
		}
		
		if ($(this.messageId))
		{
			$(this.messageId).update(this.loadCount	+ " : " +	this.loadMessage + eR);	
			Effect.Shake($(this.messageId));

			//后面显示this.loadMessage,提示信息没有改变
			setTimeout(this.removeMessage.bind(this), 3000);
		}

	},

	m : function (msg) 
	{
		this.loadMessage= msg;
		this.showMessage();
		this.failure();

	},

	isSet : function(arg)
	{
		return 'undefined' != typeof(arg) ?	true : false;
	}
};

var M = new Message('MHXZ', '发生错误', true);